package com.example.toutiao.ui.main.presenter

import com.example.toutiao.http.HttpUtils
import com.example.toutiao.http.ResponseListener
import com.example.toutiao.http.UserApi
import com.example.toutiao.mvp.model.BaseModel
import com.example.toutiao.mvp.presenter.BasePresenter
import com.example.toutiao.ui.main.model.*
import com.example.toutiao.ui.main.view.AddressView
import com.example.toutiao.ui.main.view.LoginView
import com.example.toutiao.ui.main.view.RegisterView

class AddressPresenter: BasePresenter<AddressView>() {

    /**
     * 账号注册
     */
    fun getProvince(){
        HttpUtils.sendHttp(HttpUtils.createApi(UserApi::class.java).getProvince(),object :
            ResponseListener<BaseModel<List<AddressModel>>> {
            override fun onSuccess(data: BaseModel<List<AddressModel>>) {
                if(data!=null){
                    getBaseView()!!.setData(data.data)
                }
            }

            override fun onFail(err: String) {
                getBaseView()!!.setError(err)
            }

        })
    }
    fun getCity(code:Int){
        HttpUtils.sendHttp(HttpUtils.createApi(UserApi::class.java).getCity(code),object :
            ResponseListener<BaseModel<List<AddressModel>>> {
            override fun onSuccess(data: BaseModel<List<AddressModel>>) {
                if(data!=null){
                    getBaseView()!!.setData(data.data)
                }
            }
            override fun onFail(err: String) {
                getBaseView()!!.setError(err)
            }
        })
    }
}